package com.moyq5.mvc.maker.test.bean.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.mvc.maker.test.bean.enums.SysSex;
import com.moyq5.mvc.maker.test.bean.enums.UserStatus;

/**
 * （商家）消费者（积分）信息
 * @author Moyq5
 * @date 2018年4月13日
 */
@Entity
@Table(name = "uc_user")
@DynamicUpdate
public class User implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 消费者ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "user_id")
	private Long userId;
	/**
	 * 商家
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "merch_id")
	private Merch merch;
	/**
	 * 昵称
	 */
    @Column(name = "nickname", length = 20, nullable = false)
	private String nickname;
    /**
	 * 头像
	 */
    @Column(name = "portrait", length = 200)
	private String portrait;
    /**
	 * 手机号
	 */
    @Column(name = "mobile", length = 20)
	private String mobile;
    /**
	 * 性别
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "sex", columnDefinition="int(1) default '0'")
	private SysSex sex;
    /**
     * 地区
     */
    @Column(name = "address", length = 100)
	private String address;
    /**
	 * 状态
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "status", columnDefinition="int(1) default '0'")
	private UserStatus status;
    /**
     * 剩余积分
     */
    @Column(name = "remain", nullable = false, precision = 10, scale = 0)
    private Integer remain;
    /**
     * （已）消费积分
     */
    @Column(name = "consume", nullable = false, precision = 10, scale = 0)
    private Integer consume;
    /**
	 * 微信公众号open_id
	 */
	@Column(name = "open_id", length = 30)
	private String openId;
	/**
	 * 最近登录时间
	 */
	@Column(name = "last_time", nullable = false, columnDefinition="datetime")
	private Date lastTime;
	/**
	 * 添加（注册）时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == addTime) {
			addTime = new Date();
		}
		if (null == lastTime) {
			lastTime = new Date();
		}
		if (null == status) {
			status = UserStatus.NORMAL;
		}
		if (null == remain) {
			remain = 0;
		}
		if (null == consume) {
			consume = 0;
		}
	}
	
	public Long getUserId() {
		return userId;
	}
	public void setUserId(Long userId) {
		this.userId = userId;
	}
	public Merch getMerch() {
		return merch;
	}
	public void setMerch(Merch merch) {
		this.merch = merch;
	}
	public String getNickname() {
		return nickname;
	}
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	public String getPortrait() {
		return portrait;
	}
	public void setPortrait(String portrait) {
		this.portrait = portrait;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public SysSex getSex() {
		return sex;
	}
	public void setSex(SysSex sex) {
		this.sex = sex;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public UserStatus getStatus() {
		return status;
	}
	public void setStatus(UserStatus status) {
		this.status = status;
	}
	public Integer getRemain() {
		return remain;
	}
	public void setRemain(Integer remain) {
		this.remain = remain;
	}
	public Integer getConsume() {
		return consume;
	}
	public void setConsume(Integer consume) {
		this.consume = consume;
	}
	public String getOpenId() {
		return openId;
	}
	public void setOpenId(String openId) {
		this.openId = openId;
	}
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}

	public Date getLastTime() {
		return lastTime;
	}

	public void setLastTime(Date lastTime) {
		this.lastTime = lastTime;
	}
	
}
